﻿

CREATE view [dbo].[fact_Buchungen] as
SELECT	BuchungID
		,[Buchungstag]
		,[Verwendungszweck]
		,[Betrag] as Summe
		,[Wertdatum]
		,zm.MatchString
		,zm.MatchID as ZweckID
  FROM [dbo].[99_final] k
  LEFT JOIN dbo.tblZweckMatch zm
  ON k.ZweckMatchID = zm.ZweckMatchID
  WHERE k.ZweckID_manuell is null

UNION 

SELECT	BuchungID
		,[Buchungstag]
		,[Verwendungszweck]
		,[Betrag] as Summe
		,[Wertdatum]
		,null as MatchString
		,ZweckID_manuell as ZweckID
  FROM [dbo].[99_final] k
  WHERE k.ZweckID_manuell is not null
 





